package com.hjsmallfly.syllabus.repository.lesson.remote

import com.hjsmallfly.syllabus.ext.NI
import com.hjsmallfly.syllabus.ext.from_io
import com.hjsmallfly.syllabus.repository.lesson.LessonDataSource
import com.hjsmallfly.syllabus.retrofitApi.CreditApi
import com.hjsmallfly.syllabus.room.convert.CreditLessonConvertor
import com.hjsmallfly.syllabus.room.record.LessonRecord
import rx.Observable

class LessonRemoteDataSource(private val creditApi: CreditApi) : LessonDataSource {

    override fun queryLessonDetail(cid: Long, isCache: Boolean): Observable<LessonRecord> {
        return creditApi.getLessonDetail(cid)
            .from_io()
            .map {
                CreditLessonConvertor().parse(it.data)
            }

    }

    override fun saveLesson(lesson: LessonRecord) = NI
}
